package drone.basis.base ;

import java.io.Serializable ;
import java.lang.reflect.Field ;
import java.util.Collections ;
import java.util.HashSet ;
import java.util.LinkedHashMap ;
import java.util.Map ;
import java.util.Set ;

import com.alibaba.fastjson.JSONObject ;

import drone.basis.util.HexUtil ;

public class BaseBundle implements Serializable
{

	private static final long serialVersionUID = 1L ;

	public static Set < String > EXCLUDE = Collections.synchronizedSet ( new HashSet < String > ( ) ) ;
	static
	{
		EXCLUDE.add ( "serialVersionUID" ) ;
	}

	public Map < String , Object > toMap ( )
	{
		Map < String , Object > map = new LinkedHashMap < String , Object > ( ) ;
		for ( Field field : this.getClass ( ).getDeclaredFields ( ) )
		{
			if ( EXCLUDE.contains ( field.getName ( ) ) )
			{
				continue ;
			}
			try
			{
				field.setAccessible ( true ) ;
				map.put ( field.getName ( ) , HexUtil.byte2Hex ( ( byte ) field.get ( this ) ) ) ;
			} catch ( Exception e )
			{
				continue ;
			}
		}
		return map ;
	}

	public JSONObject toJson ( )
	{
		return new JSONObject ( toMap ( ) ) ;
	}

}
